% rc9 Feb-2011 - 
%  data quality checks - b_norm, e_zero, esum, e_avg & e_03d
%
% $Id: e_zero.m 320 2005-05-05 20:07:09Z odellj $
% e_zero.m - clear counters & accumulators before averaging
%
% Ed Maclin eros_avg 12/11/02; e_avg 3/5/03
% $Log: e_zero.m,v $
% Revision 1.8  2004/09/07 19:10:26  odellj
% Cleaned up output.
%
% Revision 1.7  2004/09/07 18:35:33  odellj
% Fixed a minor conflict.
%
% Revision 1.6  2004/08/25 22:12:03  odellj
% Added the ID tag and the ability to pass that into the id_tags structure if this routine is called.
%
% Revision 1.5  2004/07/09 21:50:14  odellj
% Updated the logging of the subroutines.  Added log_file as a parameter for each of their calls.
%
% Revision 1.4  2004/07/07 18:07:53  odellj
% Prepped for logging.
%
% Revision 1.3  2004/06/30 18:13:48  odellj
% Added more verbose fprintf statements.
%
% Revision 1.2  2004/04/12 21:24:55  edmaclin
% declared SD arrays to avoid missing (n=0) bins
%
% Revision 1.1.1.1  2004/02/18 20:09:49  odellj
% initial import into CVS
%
% Revision 1.2  2004/02/05 20:43:48  odellj
% Added Id and Log tags.
%

function e_zero(log_file)
global hdr adc aac aph n2 ssdc ssac ssph nir_ph nir_ac nir_dc id_tags

fprintf('e_zero\n');

e_zero_id = '$Id: e_zero.m 320 2005-05-05 20:07:09Z odellj $';
check = strcmp(e_zero_id,id_tags); % Make sure we don't already have the tag
if sum(check) == 0
    id_tags{size(id_tags,1)+1,1} = e_zero_id;  % Add it in then.
end

% Open the log file if it exists
%
if ~strcmp(log_file,'')
    logid = fopen(log_file,'a');
else logid = 1; end

fprintf(logid,'Zeroing... (e_zero.m)\n');
n2=zeros(hdr.n_chans,hdr.n_conds); % # of trials of each condition & chan

adc=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);
aac=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);
aph=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);
ssdc=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);
ssac=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);
ssph=zeros(hdr.avg_baseline+hdr.epoch_length,hdr.n_chans,hdr.n_conds);

nir_ph=zeros(hdr.n_points,hdr.n_chans);
nir_ac=zeros(hdr.n_points,hdr.n_chans);
nir_dc=zeros(hdr.n_points,hdr.n_chans);

% initialize per channel counters (total & each accept. criterion)
%
hdr.n_good.tot=zeros(1,hdr.n_chans); % # of accepted trials for each chan
hdr.n_good.mrdc=zeros(1,hdr.n_chans);% # of mrdc accepted trials/ch
hdr.n_good.mrac=zeros(1,hdr.n_chans);
hdr.n_good.dc_range=zeros(1,hdr.n_chans);
hdr.n_good.ac=zeros(1,hdr.n_chans);
hdr.n_good.ph=zeros(1,hdr.n_chans);
hdr.n_good.mod=zeros(1,hdr.n_chans);

fprintf(logid,'Finished with e_zero...\n');
if logid ~= 1, fclose(logid); end